package com.ruoyi.cderp.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cderp.domain.CustomerSettleCheckSheet;
import com.ruoyi.cderp.service.ICustomerSettleCheckSheetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户对账单Controller
 *
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/CustomerSettleCheckSheet")
public class CustomerSettleCheckSheetController extends BaseController
{
    @Autowired
    private ICustomerSettleCheckSheetService customerSettleCheckSheetService;

    /**
     * 查询客户对账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleCheckSheet:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerSettleCheckSheet customerSettleCheckSheet)
    {
        startPage();
        List<CustomerSettleCheckSheet> list = customerSettleCheckSheetService.selectCustomerSettleCheckSheetList(customerSettleCheckSheet);
        return getDataTable(list);
    }

    /**
     * 导出客户对账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleCheckSheet:export')")
    @Log(title = "客户对账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerSettleCheckSheet customerSettleCheckSheet)
    {
        List<CustomerSettleCheckSheet> list = customerSettleCheckSheetService.selectCustomerSettleCheckSheetList(customerSettleCheckSheet);
        ExcelUtil<CustomerSettleCheckSheet> util = new ExcelUtil<CustomerSettleCheckSheet>(CustomerSettleCheckSheet.class);
        util.exportExcel(response, list, "客户对账单数据");
    }

    /**
     * 获取客户对账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleCheckSheet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(customerSettleCheckSheetService.selectCustomerSettleCheckSheetById(id));
    }

    /**
     * 新增时查询关于客户的全部类型单据
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleCheckSheet:query')")
    @GetMapping("/query")
    public AjaxResult getInfoList(
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
            @RequestParam String customerId
            )
    {
        return success(customerSettleCheckSheetService.selectFeeSheetCheckDetailList(startDate,endDate,customerId));
    }

    /**
     * 新增客户对账单
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleCheckSheet:add')")
    @Log(title = "客户对账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerSettleCheckSheet customerSettleCheckSheet)
    {
        return toAjax(customerSettleCheckSheetService.insertCustomerSettleCheckSheet(customerSettleCheckSheet));
    }

    /**
     * 修改客户对账单
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleCheckSheet:edit')")
    @Log(title = "客户对账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerSettleCheckSheet customerSettleCheckSheet)
    {
        return toAjax(customerSettleCheckSheetService.updateCustomerSettleCheckSheet(customerSettleCheckSheet));
    }

    /**
     * 删除客户对账单
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleCheckSheet:remove')")
    @Log(title = "客户对账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(customerSettleCheckSheetService.deleteCustomerSettleCheckSheetByIds(ids));
    }
}
